<!DOCTYPE html><html lang="zh-cn"><head><link rel=manifest href=/manifest.json><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="format-detection" content="telephone=no"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="icon" href="/images/icons/icon.jpg?v=2.0.0-rc.0" type="image/png" sizes="16x16"><link rel="icon" href="/images/icons/icon.jpg?v=2.0.0-rc.0" type="image/png" sizes="32x32"><meta name="description" content="对于小米营销而言，5G时代，营销的创新不能局限于传播形式。如何结合AI、IoT、OTT的能力，打通产品、媒介和渠道，真正将“万物智联”的生态运转起来，才是营销的关键。">
<meta name="keywords" content="案例,营销">
<meta property="og:type" content="article">
<meta property="og:title" content="小米的场景营销">
<meta property="og:url" content="&#x2F;2019&#x2F;12&#x2F;26&#x2F;Marketing%E2%80%94%E2%80%94%E5%B0%8F%E7%B1%B3%E5%9C%BA%E6%99%AF%E8%90%A5%E9%94%80&#x2F;">
<meta property="og:site_name" content="Olice&#39;s Blog">
<meta property="og:description" content="对于小米营销而言，5G时代，营销的创新不能局限于传播形式。如何结合AI、IoT、OTT的能力，打通产品、媒介和渠道，真正将“万物智联”的生态运转起来，才是营销的关键。">
<meta property="og:locale" content="zh-cn">
<meta property="og:updated_time" content="2022-03-30T13:18:40.000Z">
<meta name="twitter:card" content="summary"><meta name="keywords" content="Olice, Olice's Blog"><meta name="description" content="技术,生活"><title>小米的场景营销 | Olice's Blog</title><link ref="canonical" href="/2019/12/26/Marketing%E2%80%94%E2%80%94%E5%B0%8F%E7%B1%B3%E5%9C%BA%E6%99%AF%E8%90%A5%E9%94%80/"><link rel="alternate" href="/atom.xml" type="application/atom+xml"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.12.1/css/all.min.css" type="text/css"><link rel="stylesheet" href="/css/index.css?v=2.0.0-rc.0"><script>var Stun = window.Stun || {};
var CONFIG = {
  root: '/',
  algolia: undefined,
  fontIcon: {"prompt":{"success":"fas fa-check-circle","info":"fas fa-arrow-circle-right","warning":"fas fa-exclamation-circle","error":"fas fa-times-circle"},"copyBtn":"fas fa-copy"},
  sidebar: {"offsetTop":"20px","tocMaxDepth":6},
  header: {"enable":true,"showOnPost":false,"scrollDownIcon":true},
  postWidget: {"endText":true},
  nightMode: {"enable":true},
  back2top: {"enable":true},
  codeblock: {"style":"default","highlight":"ocean","wordWrap":false},
  reward: false,
  fancybox: false,
  zoomImage: {"gapAside":"20px"},
  galleryWaterfall: undefined,
  lazyload: false,
  pjax: undefined,
  externalLink: {"icon":{"enable":true,"name":"fas fa-external-link-alt"}},
  shortcuts: {"switchPost":true},
  prompt: {"copyButton":"Copy","copySuccess":"Copy Success","copyError":"Copy Error"},
  sourcePath: {"js":"js","css":"css","images":"images"},
};

window.CONFIG = CONFIG;</script></head><body><div class="container" id="container"><header class="header" id="header"><div class="header-inner header-inner--height header-inner--bgcolor"><nav class="header-nav header-nav--sticky"><div class="header-nav-inner"><div class="header-nav-menubtn"><i class="fas fa-bars"></i></div><div class="header-nav-menu"><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/"><span class="header-nav-menu-item__icon"><i class="fas fa-home"></i></span><span class="header-nav-menu-item__text">Home</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/archives/"><span class="header-nav-menu-item__icon"><i class="fas fa-folder-open"></i></span><span class="header-nav-menu-item__text">Archives</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/categories/"><span class="header-nav-menu-item__icon"><i class="fas fa-layer-group"></i></span><span class="header-nav-menu-item__text">Categories</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/tags/"><span class="header-nav-menu-item__icon"><i class="fas fa-tags"></i></span><span class="header-nav-menu-item__text">Tags</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="javascript:;" onclick="return false;"><span class="header-nav-menu-item__icon"><i class="fa fa-address-book"></i></span><span class="header-nav-menu-item__text">友链</span></a><div class="header-nav-submenu"><div class="header-nav-submenu-item"><a class="header-nav-submenu-item__link" href="https://mikyming.online/"><span class="header-nav-submenu-item__text">BobbyRong</span></a></div></div></div></div><div class="header-nav-search"><span class="header-nav-search__icon"><i class="fas fa-search"></i></span><span class="header-nav-search__text">Search</span></div><div class="header-nav-mode"><div class="mode"><div class="mode-track"><span class="mode-track-moon"></span><span class="mode-track-sun"></span></div><div class="mode-thumb"></div></div></div></div></nav></div></header><main class="main" id="main"><div class="main-inner"><div class="content-wrap" id="content-wrap"><div class="content" id="content"><!-- Just used to judge whether it is an article page--><div id="is-post"></div><div class="post"><header class="post-header"><h1 class="post-title">小米的场景营销</h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">Created</span><span class="post-meta-item__value">2019-12-26</span></span><span class="post-meta-item post-meta-item--wordcount"><span class="post-meta-item__icon"><i class="far fa-file-word"></i></span><span class="post-meta-item__info">Words</span><span class="post-meta-item__value">2.1k</span></span><span class="post-meta-item post-meta-item--visitors"><span class="post-meta-item__icon" data-popover="Visitors" data-popover-pos="up"><i class="fas fa-eye"></i></span><span class="post-meta-item__value" id="busuanzi_value_page_pv"></span></span></div></header><div class="post-body"><p>对于小米营销而言，5G时代，营销的创新不能局限于传播形式。如何结合AI、IoT、OTT的能力，打通产品、媒介和渠道，真正将“万物智联”的生态运转起来，才是营销的关键。</p>
<a id="more"></a>


        <h2 id="小米公司场景营销策略的独特性"   >
          <a href="#小米公司场景营销策略的独特性" class="heading-link"><i class="fas fa-link"></i></a>小米公司场景营销策略的独特性</h2>
      
        <h3 id="小米的优势—底层核心系统能力"   >
          <a href="#小米的优势—底层核心系统能力" class="heading-link"><i class="fas fa-link"></i></a>小米的优势—底层核心系统能力</h3>
      <p>小米营销是源自于小米生态的营销平台，其价值同样是由小米生态的价值属性决定。</p>

        <h4 id="第一：小米有粉丝"   >
          <a href="#第一：小米有粉丝" class="heading-link"><i class="fas fa-link"></i></a>第一：小米有粉丝</h4>
      <p>小米是“一家以手机、智能硬件和IoT平台为核心的互联网公司”，雷军说小米是铁人三项：硬件、互联网和新零售，小米是互联网手机开创者，是世界第四大手机巨头，与用户“交朋友”的小米更是粉丝经济的发明者，跟米粉有深度连接，截至目前MIUI月活2.92亿，月活超千万小米应用38个，小米有很好的群众基础。</p>

        <h4 id="第二：小米有内容与服务生态。"   >
          <a href="#第二：小米有内容与服务生态。" class="heading-link"><i class="fas fa-link"></i></a>第二：小米有内容与服务生态。</h4>
      <p>手机卖出去对很多手机公司是结束，对小米却是用户经营的开始，多年来小米持续地在MIUI生态上构建了全面的内容和服务体系。不只是有众多手机厂商都有的应用市场等基础应用，同时还拥有38个月活千万+的自有应用，四大系统入口（浏览器、搜索引擎、内容中心和智能助理）则形成了操作系统层面的内容和服务中心。<br>基于四大系统入口（浏览器、搜索引擎、内容中心和智能助理），小米让用户更多用小米的内容与服务，构建流量闭环。<br>信息流日活在2019年超过2000万，2020年将达到2500万，每日分发量已达到15亿，日均用户时长50分钟；可搜索全网内容，桌面搜索框整体活跃度30%，即10个小米用户有3个用系统内置搜索，首屏结果满足率达到68%；负一屏智能助理日活全年上涨62%，日服务分发量5.6亿。<br>看这组数据你可能以为是字节跳动或者百度的数据，实际却是小米。内容与服务的闭环意味着更多的用户时长，以及更多的营销机会。</p>

        <h4 id="第三：小米有IoT生态。"   >
          <a href="#第三：小米有IoT生态。" class="heading-link"><i class="fas fa-link"></i></a>第三：小米有IoT生态。</h4>
      <p>小米不只是一家智能手机公司，更是一家智能硬件公司，一个以AIoT为入口的内容+服务生态。小米拥有1+4+N的硬件入口（1是手机，4是电视、音箱、笔记本和路由器，N则是生态链中的众多产品）。在硬件基座上，小米基于MIUI、OTT和小爱同学三大平台，打通了内容和服务生态，其中小米电视累积激活量达到3200万，月活用户2390万，日活用户1400万，日均市场4.4小时，日均播放量1.52亿次，已是中国智能家居第一入口；小米AIoT平台连接智能设备超过2.1亿台，同比增长62%；小爱同学则是最活跃的语音交互平台，月活5790万，累计唤醒次数341亿次。 </p>

        <h2 id="小米营销策略的独特性"   >
          <a href="#小米营销策略的独特性" class="heading-link"><i class="fas fa-link"></i></a>小米营销策略的独特性</h2>
      
        <h3 id="小米构建基于IoT生态的场景连贯性"   >
          <a href="#小米构建基于IoT生态的场景连贯性" class="heading-link"><i class="fas fa-link"></i></a>小米构建基于IoT生态的场景连贯性</h3>
      <p>例如机场看到一个阿里云的广告，接着在航空杂志上再次看到了阿里云的广告，最后下飞机打开手机又看到了阿里云在一个媒体的广告，不同场景连续看了三次阿里云的广告，这是一种营销的“连贯性”，在用户注意力碎片化时，靠一次哪怕刷屏的广告去击中用户是远远不够的，只有靠多场景、高频率和全时段地密集轰炸，才能真正影响用户。<br>营销的连贯性很重要，前提是场景的连贯性。小米最大的独特性就是基于IoT生态，构建了这样的连贯性。一个超级App再强，拥有再多用户时间，都只占据用户的一个或者几个场景，对用户的洞察是局部的，对用户的影响的断点的。小米不然，小米手机内的一切场景都是小米可控的场景。就算用户不用手机了，在路上，在公司，在家里同样可能成为小米IoT用户。总之，小米具有全场景、全链路、全时段的穿透能力，而不是单点影响，因此具有更强的渗透力和穿透力，品牌可以通过小米连贯性去在不同场景下持续、接力和多次地影响用户。</p>

        <h3 id="小米营销的场景性"   >
          <a href="#小米营销的场景性" class="heading-link"><i class="fas fa-link"></i></a>小米营销的场景性</h3>
      <p>没有用户喜欢广告，曾经用户没有选择，现在用户可以通过会员等方式去避开广告。看不看广告是用户说了算，今天的用户已经越来越讨厌强制、单向和填鸭广告，正是因为此，品牌一定要贴合场景，让广告变为用户价值的一部分，让广告成为一种内容或者服务，让广告成为一个拥有用户体验的产品。<br>小米拥有线上线下大量的服务场景，用户不论是学习、工作、睡觉、娱乐、出行还是购物都会用到小米的软硬件或者服务，进而被小米洞察和影响。<br>比如拥有小米一级入口的服务分发中心“负一屏智能助理”围绕用户日常生活进行场景化设计，每天分发服务量高达5.6亿，它可以智能预测用户可能需要的服务，可以对用户正在使用的服务进行智能提醒，从上班到购物到家庭到出行……用户叫了滴滴就可以收到滴滴提醒，寄了顺丰就会看到快递最新进展，自选了股票就可以看到股票最新动态，预订了酒店就可以看到最新的出行日程提醒……这些服务本身就是用户所需，中间有许多场景化营销的机会，小米正在招募更多优质伙伴，同时给品牌提供活动红包、场景定制、热点运营等场景营销产品。<br>每个品牌不同时间有不同营销需求，小米如此多的场景，总有至少一样适合品牌场景营销需求。</p>

        <h3 id="小米丰富的内容营销"   >
          <a href="#小米丰富的内容营销" class="heading-link"><i class="fas fa-link"></i></a>小米丰富的内容营销</h3>
      <p>今天最好的广告就是让用户感受不到广告的存在，营销要做到“润物细无声”最佳手段就是内容营销，让广告变为有价值的内容。小米拥有短视频、直播、长视频、VLOG、音乐、二次元、画报诸多内容类型，通过信息流、OTT、小爱同学和智能音箱等服务，满足不同年龄层用户（儿童、年轻人、中年、老年）的内容消费需求。小米图文信息流每日分发数20亿+，长视频OTT日均总播放次数1.52亿，音乐和有声读物每日播放超过9000万首，已经是一个规模庞大的内容分发平台，跟字节跳动、百度、腾讯们的内容价值一样。<br>基于此，小米形成了丰富的内容营销产品，而小米的独特性在于，其拥有AIoT生态。百度分发靠搜索，字节跳动靠信息流，腾讯靠社交，小米则是全场景分发。小米内容分发形式包括信息流、搜索、OTT视频、小爱同学等等，分发到1+4+N的成百上千中AIoT设备中，满足用户全场景内容消费需求，可以跟AIoT场景结合，是小米营销的最大独特性。<br>小米在AIoT上形成的全场景优势让其在营销上具有独特性，已快速成长为头部营销平台。</p>

        <h2 id="结语"   >
          <a href="#结语" class="heading-link"><i class="fas fa-link"></i></a>结语</h2>
      <p>对于小米营销而言，5G时代，营销的创新不能局限于传播形式。如何结合AI、IoT、OTT的能力，打通产品、媒介和渠道，真正将“万物智联”的生态运转起来，才是营销的关键。</p>
</div><footer class="post-footer"><div class="post-ending ending"><div class="ending__text">------ END ------</div></div><div class="post-copyright copyright"><div class="copyright-author"><span class="copyright-author__name">Author: </span><span class="copyright-author__value"></span></div><div class="copyright-link"><span class="copyright-link__name">Link: </span><span class="copyright-link__value"></span></div><div class="copyright-notice"><span class="copyright-notice__name">Copyright: </span><span class="copyright-notice__value">All articles in this blog are licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh-cn" rel="external nofollow" target="_blank">BY-NC-SA</a> unless stating additionally</span></div></div><div class="post-tags"><span class="post-tags-item"><span class="post-tags-item__icon"><i class="fas fa-tag"></i></span><a class="post-tags-item__link" href="/tags/%E6%A1%88%E4%BE%8B/">案例</a></span><span class="post-tags-item"><span class="post-tags-item__icon"><i class="fas fa-tag"></i></span><a class="post-tags-item__link" href="/tags/%E8%90%A5%E9%94%80/">营销</a></span></div><nav class="post-paginator paginator"><div class="paginator-prev"><a class="paginator-prev__link" href="/2020/04/11/%E4%B8%8E%E8%87%AA%E5%B7%B1%E5%AF%B9%E8%AF%9D%E2%80%94%E8%AF%A5%E4%B8%8D%E8%AF%A5%E8%80%83%E7%A0%94/"><span class="paginator-prev__icon"><i class="fas fa-angle-left"></i></span><span class="paginator-prev__text">该不该考研</span></a></div></nav></footer></div></div></div><div class="sidebar-wrap" id="sidebar-wrap"><aside class="sidebar" id="sidebar"><div class="sidebar-nav"><span class="sidebar-nav-toc current">Catalog</span><span class="sidebar-nav-ov">Overview</span></div><section class="sidebar-toc"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#小米公司场景营销策略的独特性"><span class="toc-number">1.</span> <span class="toc-text">
          小米公司场景营销策略的独特性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#小米的优势—底层核心系统能力"><span class="toc-number">1.1.</span> <span class="toc-text">
          小米的优势—底层核心系统能力</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#第一：小米有粉丝"><span class="toc-number">1.1.1.</span> <span class="toc-text">
          第一：小米有粉丝</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#第二：小米有内容与服务生态。"><span class="toc-number">1.1.2.</span> <span class="toc-text">
          第二：小米有内容与服务生态。</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#第三：小米有IoT生态。"><span class="toc-number">1.1.3.</span> <span class="toc-text">
          第三：小米有IoT生态。</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#小米营销策略的独特性"><span class="toc-number">2.</span> <span class="toc-text">
          小米营销策略的独特性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#小米构建基于IoT生态的场景连贯性"><span class="toc-number">2.1.</span> <span class="toc-text">
          小米构建基于IoT生态的场景连贯性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#小米营销的场景性"><span class="toc-number">2.2.</span> <span class="toc-text">
          小米营销的场景性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#小米丰富的内容营销"><span class="toc-number">2.3.</span> <span class="toc-text">
          小米丰富的内容营销</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#结语"><span class="toc-number">3.</span> <span class="toc-text">
          结语</span></a></li></ol></section><!-- ov = overview--><section class="sidebar-ov hide"><div class="sidebar-ov-author"><div class="sidebar-ov-author__avatar"><img class="sidebar-ov-author__avatar_img" src="/images/icons/olice.jpg" alt="avatar"></div><p class="sidebar-ov-author__text">love life</p></div><div class="sidebar-ov-social"><a class="sidebar-ov-social-item" href="mailto:398700412@qq.com" target="_blank" rel="noopener" data-popover="social.email" data-popover-pos="up"><span class="sidebar-ov-social-item__icon"><i class="fas fa-envelope"></i></span></a></div><div class="sidebar-ov-feed"><span class="sidebar-ov-feed-rss"><a class="sidebar-ov-feed-rss__link" href="/atom.xml" target="_blank" rel="noopener"><span class="sidebar-ov-feed-rss__icon"><i class="fas fa-rss"></i></span><span>RSS Subscribe</span></a></span></div><div class="sidebar-ov-state"><a class="sidebar-ov-state-item sidebar-ov-state-item--posts" href="/archives/"><div class="sidebar-ov-state-item__count">20</div><div class="sidebar-ov-state-item__name">Archives</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--categories" href="/categories/"><div class="sidebar-ov-state-item__count">5</div><div class="sidebar-ov-state-item__name">Categories</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--tags" href="/tags/"><div class="sidebar-ov-state-item__count">22</div><div class="sidebar-ov-state-item__name">Tags</div></a></div><div class="sidebar-ov-cc"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh-cn" target="_blank" rel="noopener" data-popover="Creative Commons" data-popover-pos="up"><img src="/images/cc-by-nc-sa.svg"></a></div></section><div class="sidebar-reading"><div class="sidebar-reading-info"><span class="sidebar-reading-info__text">You have read </span><span class="sidebar-reading-info__num">0</span></div><div class="sidebar-reading-line"></div></div></aside></div><div class="clearfix"></div></div></main><footer class="footer" id="footer"><div class="footer-inner"><div><span>Copyright © 2022</span><span class="footer__icon"><i class="fas fa-heart"></i></span><span>Olice</span></div><div><span>Powered by <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a></span><span> v4.0.0</span><span class="footer__devider">|</span><span>Theme - <a href="https://github.com/liuyib/hexo-theme-stun/" title="Stun" target="_blank" rel="noopener">Stun</a></span><span> v2.0.0-rc.0</span></div><div class="busuanzi"><span class="busuanzi-siteuv"><span class="busuanzi-siteuv__icon" data-popover-pos="up" data-popover="Unique Visitor"><i class="fas fa-user"></i></span><span class="busuanzi-siteuv__value" id="busuanzi_value_site_uv"></span></span><span class="busuanzi-sitepv"><span class="busuanzi-siteuv__icon" data-popover-pos="up" data-popover="Page View"><i class="fas fa-eye"></i></span><span class="busuanzi-siteuv__value" id="busuanzi_value_site_pv"></span></span></div></div></footer><div class="loading-bar" id="loading-bar"><div class="loading-bar__progress"></div></div><div class="back2top" id="back2top"><span class="back2top__icon"><i class="fas fa-rocket"></i></span></div></div><div class="search-mask"></div><div class="search-popup"><span class="search-close"></span><div class="search-input"><input placeholder="Search for Posts (Support multiple keywords)"></div><div class="search-results"></div></div><script src="https://cdn.jsdelivr.net/npm/jquery@v3.4.1/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.ui.min.js"></script><script src="https://cdn.jsdelivr.net/npm/ribbon.js@latest/dist/ribbon.min.js" size="120" alpha="0.6" zIndex="-1"></script><script>function initSearch() {
  var isXML = true;
  var search_path = 'search.json';

  if (!search_path) {
    search_path = 'search.xml';
  } else if (/json$/i.test(search_path)) {
    isXML = false;
  }

  var path = '/' + search_path;
  $.ajax({
    url: path,
    dataType: isXML ? 'xml' : 'json',
    async: true,
    success: function (res) {
      var datas = isXML ? $('entry', res).map(function () {
        // 将 XML 转为 JSON
        return {
          title: $('title', this).text(),
          content: $('content', this).text(),
          url: $('url', this).text()
        };
      }).get() : res;
      var $input = $('.search-input input');
      var $result = $('.search-results');
      // 搜索对象（标题、内容）的权重，影响显示顺序
      var WEIGHT = { title: 100, content: 1 };
      var searchPost = function () {
        var searchText = $input.val().toLowerCase().trim();
        // 根据空白字符分隔关键字
        var keywords = searchText.split(/[\s]+/);
        // 搜索结果
        var matchPosts = [];

        // 有多个关键字时，将原文字整个保存下来
        if (keywords.length > 1) {
          keywords.push(searchText);
        }
        // 防止未输入字符时搜索
        if (searchText.length > 0) {
          datas.forEach(function (data) {
            var isMatch  = false;
            // 没有标题的文章使用预设的 i18n 变量代替
            var title = (data.title && data.title.trim()) || '[ Untitled ]';
            var titleLower = title && title.toLowerCase();
            // 删除 HTML 标签 和 所有空白字符
            var content = data.content && data.content.replace(/<[^>]+>/g, '');
            var contentLower = content && content.toLowerCase();
            // 删除重复的 /
            var postURL = data.url && decodeURI(data.url).replace(/\/{2,}/g, '/');
            // 标题中匹配到的关键词
            var titleHitSlice = [];
            // 内容中匹配到的关键词
            var contentHitSlice = [];

            keywords.forEach(function (keyword) {
              /**
              * 获取匹配的关键词的索引
              * @param {String} keyword 要匹配的关键字
              * @param {String} text 原文字
              * @param {Boolean} caseSensitive 是否区分大小写
              * @param {Number} weight 匹配对象的权重。权重大的优先显示
              * @return {Array}
              */
              function getIndexByword (word, text, caseSensitive, weight) {
                if (!word || !text) {
                  return [];
                };

                var startIndex = 0; // 每次匹配的开始索引
                var index = -1;     // 匹配到的索引值
                var result = [];    // 匹配结果

                if (!caseSensitive) {
                  word = word.toLowerCase();
                  text = text.toLowerCase();
                }

                while((index = text.indexOf(word, startIndex)) !== -1) {
                  var hasMatch = false;
                  // 索引位置相同的关键词，保留长度较长的
                  titleHitSlice.forEach(function (hit) {
                    if (hit.index === index && hit.word.length < word.length) {
                      hit.word = word;
                      hasMatch = true;
                    }
                  });
                  startIndex = index + word.length;
                  !hasMatch && result.push({ index: index, word: word, weight: weight });
                }
                return result;
              }
              titleHitSlice = titleHitSlice.concat(getIndexByword(keyword, titleLower, false, WEIGHT.title));
              contentHitSlice = contentHitSlice.concat(getIndexByword(keyword, contentLower, false, WEIGHT.content));
            });

            var hitTitle = titleHitSlice.length;
            var hitContent = contentHitSlice.length;

            if (hitTitle > 0 || hitContent > 0) {
              isMatch = true;
            }
            if (isMatch) {
              ;[titleHitSlice, contentHitSlice].forEach(function (hit) {
                // 按照匹配文字的索引的递增顺序排序
                hit.sort(function (left, right) {
                  return left.index - right.index;
                });
              });
              /**
              * 给文本中匹配到的关键词添加标记，从而进行高亮显示
              * @param {String} text 原文本
              * @param {Array} hitSlice 匹配项的索引信息
              * @param {Number} start 开始索引
              * @param {Number} end 结束索引
              * @return {String}
              */
              function highlightKeyword (text, hitSlice, start, end) {
                if (!text || !hitSlice || !hitSlice.length) {
                  return;
                }

                var result = '';
                var startIndex = start;
                var endIndex = end;
                hitSlice.forEach(function (hit) {
                  if (hit.index < startIndex) {
                    return;
                  }

                  var hitWordEnd = hit.index + hit.word.length;
                  result += text.slice(startIndex, hit.index);
                  result += '<b>' + text.slice(hit.index, hitWordEnd) + '</b>';
                  startIndex = hitWordEnd;
                });
                result += text.slice(startIndex, endIndex);
                return result;
              }

              var postData = {};
              // 文章总的搜索权重
              var postWeight = titleHitSlice.length * WEIGHT.title + contentHitSlice.length * WEIGHT.content;
              // 标记匹配关键词后的标题
              var postTitle = highlightKeyword(title, titleHitSlice, 0, title.length) || title;
              // 标记匹配关键词后的内容
              var postContent;
              // 显示内容的长度
              var SHOW_WORD_LENGTH = 200;
              // 命中关键词前的字符显示长度
              var SHOW_WORD_FRONT_LENGTH = 20;
              var SHOW_WORD_END_LENGTH = SHOW_WORD_LENGTH - SHOW_WORD_FRONT_LENGTH;

              // 截取匹配的第一个字符，前后共 200 个字符来显示
              if (contentHitSlice.length > 0) {
                var firstIndex = contentHitSlice[0].index;
                var start = firstIndex > SHOW_WORD_FRONT_LENGTH ? firstIndex - SHOW_WORD_FRONT_LENGTH : 0;
                var end = firstIndex + SHOW_WORD_END_LENGTH;
                postContent = highlightKeyword(content, contentHitSlice, start, end);
              } else { // 未匹配到内容，直接截取前 200 个字符来显示
                postContent = content.slice(0, SHOW_WORD_LENGTH);
              }
              postData.title = postTitle;
              postData.content = postContent;
              postData.url = postURL;
              postData.weight = postWeight;
              matchPosts.push(postData);
            }
          });
        }

        var resultInnerHtml = '';
        if (matchPosts.length) {
          // 按权重递增的顺序排序，使权重大的优先显示
          matchPosts.sort(function (left, right) {
            return right.weight - left.weight;
          });
          resultInnerHtml += '<ul>';
          matchPosts.forEach(function (post) {
            resultInnerHtml += '<li><a class="search-results-title" href="' + post.url + '">';
            resultInnerHtml += post.title;
            resultInnerHtml += '</a><div class="search-results-content">';
            resultInnerHtml += post.content;
            resultInnerHtml += '</div></li>';
          });
          resultInnerHtml += '</ul>';
        } else {
          resultInnerHtml += '<div class="search-results-none"><i class="far fa-meh"></i></div>';
        }
        $result.html(resultInnerHtml);
      };
      $input.on('input', searchPost);
      $input.on('keyup', function (e) {
        if (e.keyCode === Stun.utils.codeToKeyCode('Enter')) {
          searchPost();
        }
      });
    }
  });
}

function closeSearch () {
  $('body').css({ overflow: 'auto' });
  $('.search-popup').css({ display: 'none' });
  $('.search-mask').css({ display: 'none' });
}

window.addEventListener('DOMContentLoaded', function () {
  Stun.utils.pjaxReloadLocalSearch = function () {
    $('.header-nav-search').on('click', function (e) {
      e.stopPropagation();
      $('body').css('overflow', 'hidden');
      $('.search-popup')
        .velocity('stop')
        .velocity('transition.expandIn', {
          duration: 300,
          complete: function () {
            $('.search-popup input').focus();
          }
        });
      $('.search-mask')
        .velocity('stop')
        .velocity('transition.fadeIn', {
          duration: 300
        });

      initSearch();
    });
    $('.search-mask, .search-close').on('click', function () {
      closeSearch();
    });
    $(document).on('keydown', function (e) {
      // Escape <=> 27
      if (e.keyCode === Stun.utils.codeToKeyCode('Escape')) {
        closeSearch();
      }
    });
  };

  Stun.utils.pjaxReloadLocalSearch();
}, false);</script><script src="https://cdn.jsdelivr.net/gh/sukkaw/busuanzi@latest/bsz.pure.mini.js" async></script><script src="/js/utils.js?v=2.0.0-rc.0"></script><script src="/js/stun-boot.js?v=2.0.0-rc.0"></script><script src="/js/scroll.js?v=2.0.0-rc.0"></script><script src="/js/header.js?v=2.0.0-rc.0"></script><script src="/js/sidebar.js?v=2.0.0-rc.0"></script><script>if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw.js?t=1648792074904')
    .then(function () {console.log('ServiceWorker Register Successfully.')})
    .catch(function (e) {console.error(e)});
}
</script></body></html>